unit io_ImageCapture_output;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, basicio_output, Controls, basicio_city, basicio_street,
  io_imagecapture_const, basicio_field, basicio_trade, basicio_resources;

type
  { TIOOutput }

  { TIO_ImageCapture_Output }

  TIO_ImageCapture_Output = class(TIOOutput)
    protected
      procedure ClickOften(AX,AY,ACount: Integer);
      procedure MouseClick(Ax, Ay: Integer);
      procedure BeginBuildCity();
      procedure BeginBuildStreet();
      procedure BeginExtendCity;
    protected
      procedure KeyEvent(APressed: boolean; AKey: Word); virtual; abstract;
      procedure MouseMove(Ax,Ay: Integer); virtual; abstract;
      procedure MouseEvent(APressed: boolean; Ax, Ay: Integer); virtual; abstract;
    public
      constructor Create;
      destructor Destroy; override;
      procedure BuildCity(APos: TCityPosition); override;
      procedure BuildStreet(APos: TStreetPosition); override;
      procedure ExtendCity(APos: TCityPosition); override;
      procedure MoveThief(APos: TFieldPosition); override;
      procedure GenerateTradeOffer(AOffer: TTradeOffer); override;
      procedure ThrowRes(ARes: TResources); override;
      procedure EndTurn; override;
      procedure ThiefCity(APos: TCityPosition); override;
      procedure BuildInvention; override;
  end;

implementation

{ TIO_ImageCapture_Output }

constructor TIO_ImageCapture_Output.Create;
begin
  inherited;
end;

destructor TIO_ImageCapture_Output.Destroy;
begin
  inherited Destroy;
end;

procedure TIO_ImageCapture_Output.BuildCity(APos: TCityPosition);
var
  position: TPoint;
begin
  inherited;
  position:= CityCorToPos(APos);
  BeginBuildCity;
  MouseClick(position.x+FieldRect.Left, position.y+FieldRect.Top);
end;

procedure TIO_ImageCapture_Output.BeginBuildCity;
begin
  inherited;
  MouseClick(820, 90)
end;

procedure TIO_ImageCapture_Output.BuildStreet(APos: TStreetPosition);
var
  position: TPoint;
begin
  inherited;
  position:= StreetCorToPos(APos);
  BeginBuildStreet;
  MouseClick(position.x+FieldRect.Left, position.y+FieldRect.Top);
end;

procedure TIO_ImageCapture_Output.BeginBuildStreet;
begin
  inherited;
  MouseClick(920, 75)
end;

procedure TIO_ImageCapture_Output.ExtendCity(APos: TCityPosition);
var
  position: TPoint;
begin
  inherited;
  position:= CityCorToPos(APos);
  BeginExtendCity;
  MouseClick(position.x+FieldRect.Left, position.y+FieldRect.Top);
end;

procedure TIO_ImageCapture_Output.BeginExtendCity;
begin
  inherited;
  MouseClick(734, 98);
end;

procedure TIO_ImageCapture_Output.MoveThief(APos: TFieldPosition);
var
  position: TPoint;
begin
  inherited;
  position:= FieldCorToPos(APos);
  MouseClick(position.x, position.y)
end;

procedure TIO_ImageCapture_Output.GenerateTradeOffer(AOffer: TTradeOffer);
var
  WeGet: TResources;
  TheyGet: TResources;
begin
  inherited GenerateTradeOffer(AOffer);
  WeGet:= AOffer.WeGet;
  TheyGet:= AOffer.TheyGet;
  //selects resources to receive
  MouseClick(941, 233);

  ClickOften(920, 188, WeGet.Wood-1);
  ClickOften(1030, 188, WeGet.Wheat-1);
  ClickOften(956, 188, WeGet.Dirt-1);
  ClickOften(1068, 188, WeGet.Ore-1);
  ClickOften(994, 188, WeGet.Sheeps-1);

  //selects resources to give away
  MouseClick(1014, 233);

  ClickOften(920, 188, TheyGet.Wood-1);
  ClickOften(1030, 188, TheyGet.Wheat-1);
  ClickOften(956, 188, TheyGet.Dirt-1);
  ClickOften(1068, 188, TheyGet.Ore-1);
  ClickOften(994, 188, TheyGet.Sheeps-1);

  //sends offer
  MouseClick(975, 300);
end;

procedure TIO_ImageCapture_Output.ThrowRes(ARes: TResources);
begin
  inherited ThrowRes(ARes);
  ClickOften(686, 588, ARes.Wood-1);
  ClickOften(960,581,ARes.Wheat-1);
  ClickOften(779,581,ARes.Dirt-1);
  ClickOften(1050,581, ARes.Ore-1);
  ClickOften(870,581, ARes.Sheeps-1)
end;

procedure TIO_ImageCapture_Output.EndTurn;
begin
  inherited EndTurn;
  MouseClick(705, 300)
end;

procedure TIO_ImageCapture_Output.ThiefCity(APos: TCityPosition);
var
  position: TPoint;
begin
  inherited ThiefCity(APos);
  position:= CityCorToPos(APos);
  MouseClick(position.x+FieldRect.Left, position.y+FieldRect.Top);
end;

procedure TIO_ImageCapture_Output.MouseClick(Ax, Ay: Integer);
begin
  MouseEvent(true,Ax,Ay);
  sleep(50);
  MouseEvent(false,Ax,Ay);
end;

procedure TIO_ImageCapture_Output.ClickOften(AX,AY,ACount: Integer);
var
  i: integer;
begin
  for i:=0 to ACount do
  begin
    MouseClick(AX, AY);
  end;
end;

procedure TIO_ImageCapture_Output.BuildInvention;
begin
  MouseClick(1000,80);
end;

end.

